package com.example.design.singleton;

/**
 * 单例模式 ： 懒汉型        加载的时候没有初始化会导致线程抢占问题 线程不安全
 *
 */
public class Singleton2 {

    //类加载的时候就进行初始化
        public  static  Singleton2   instance;

        private  Singleton2(){
            System.out.println("构造方法。。。。。");
        }

        public  static  Singleton2 getInstance(){

            return instance==null?instance=new Singleton2():instance;

        }
}

class   SingleTest2{
    public static void main(String[] args) {
        Singleton2 singleton1=Singleton2.getInstance();
        Singleton2 singleton2=Singleton2.getInstance();


        System.out.println(singleton1==singleton2);
    }
}
